package com.cn.crmsystem.controller.customerController;

import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.customerService.ClueService;
import com.cn.crmsystem.service.customerService.CustomerService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value ="客户数据test",tags ="客户数据接口API")
@Controller
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @ResponseBody
    @RequestMapping(value = "/insertCustomer",method = RequestMethod.POST)
    @ApiOperation(value ="新增客户数据接口",notes = "填写客户基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "customer",value = "客户基本信息",required = false)
    public ResultJson insertClue(@RequestBody Customer customer){
        System.out.println(customer.getName()+"****");
        Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setUser_id(1);
        System.out.println(login.getId());
        return  customerService.insertCustomer(customer,login);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteCustomer",method = RequestMethod.POST)
    @ApiOperation(value ="删除客户数据接口",notes = "传入要删除的客户数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "客户数据id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson deleteCustomer(Integer id){
        System.out.println(id);
        return customerService.deleteCustomer(id);
    }
    @ResponseBody
    @RequestMapping(value = "/addCustomerFollow",method = RequestMethod.POST)
    @ApiOperation(value ="新增客户跟进数据接口",notes = "填写客户跟进基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "follow_Up",value = "跟进基本信息",required = false)
    public ResultJson addCustomerFollow(@RequestBody Follow_Up follow_Up){
         Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setId(1);
        System.out.println(login.getId());
        return customerService.addCustomerFollow(login,follow_Up);
    }

    @ResponseBody
    @RequestMapping(value = "/updateCustomer",method = RequestMethod.POST)
    @ApiOperation(value ="修改客户数据接口",notes = "填写修改后客户基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "customer",value = "修改后客户基本信息",required = false)
    public ResultJson updateCustomer(@RequestBody Customer customer) {
        System.out.println(customer.getName() + "****");

        //User user = (User) SecurityUtils.getSubject().getPrincipal();
        return customerService.updateCustomer(customer);
    }

    @ResponseBody
    @RequestMapping(value = "/updateCustomerUser",method = RequestMethod.POST)
    @ApiOperation(value ="修改客户负责人数据接口",notes = "传入修改后的负责人id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "修改后的负责人id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson updateCustomerUser(@RequestBody User user) {
        return customerService.updateCustomerUser(user);
    }

    @ResponseBody
    @RequestMapping(value = "/selectCustomer",method = RequestMethod.POST)
    @ApiOperation(value ="条件查询客户数据接口",notes = "填写筛选条件数据",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "客户名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "industry",value = "客户行业",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "level",value = "客户级别",paramType = "query",dataType = "Integer",required = false),
            @ApiImplicitParam(name = "user_name",value = "负责人名字",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "create_name",value = "创建人名字",paramType = "query",dataType = "String",required = false)
    })
    public ResultJson<List> selectCustomer(@RequestBody @RequestParam @ApiParam(required = false) Map<String,Object> map) {
        return customerService.selectCustomer(map);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteAllCustomer",method = RequestMethod.POST)
    @ApiOperation(value ="批量删除客户数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "ids",value = "客户id",paramType = "query",dataType = "String",required = false)
    public ResultJson deleteAllCustomer(Integer[] ids){
        System.out.println(ids.length);
        return customerService.deleteAllCustomer(ids);

    }

}
